/*
 * @Author: 王雁鹏
 * @Date: 2023-06-07 21:30:29
 * @LastEditTime: 2023-06-08 21:42:22
 * @LastEditors: Please set LastEditors
 * @Description: 
 * @FilePath: \expressf:\web-vue\bs-nodejs-background-code\routes\tag\service.js
 * -------------------------------------
 */
const request = require('request');
var req = require("../../utils/router");
const db = require("../../mysql/index.js");
const config = require("./config.js");
const { generateUUID } = require("../../utils/func.js")
let { router, GetRouter, PostRouter } = req
// 设置菜单
new PostRouter().send('/setTag', function (res, data) {
    let { id, name } = data
    let condition = { name, code: id ? undefined : generateUUID() }
    db.setData({
        ...config,
        id,
        condition
    }, (rows, fields) => {
        res.send({ code: 200, data: rows });
    })
})
// 获取菜单
new GetRouter().send('/getTag', (res, data) => {
    let { pageSize, pageNum, name } = data
    let obj = { name: db.LIKE({ ...config, select: { name } }) }
    let select = db.Params(obj)
    db.select({
        ...config,
        select,
        pageSize, pageNum
    }, (rows) => {
        res.send({ code: 200, data: rows });
    })
})
// 删除菜单
new GetRouter().send('/delTag', (res, data) => {
    let { id } = data
    let obj = { id: db.EQ({ ...config, select: { id } }) }
    let select = db.Params(obj)
    db.delete({
        ...config,
        select,
    }, (rows) => {
        res.send({ code: 200, data: rows });
    })
})
module.exports = router